home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Snippets
/
PopupMenu Tester 1.0.3
/
Tester.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-07
|
3KB
|
132 lines
/* ----------------------------------------------------------------------
PopupMenu Tester
version 1.0.3
Written by: Paul Celestin
This simple application demonstrates the use of a System-7 popup menu,
as well as a movable modal dialog. It doesn't do much else, but maybe
it has something to offer to someone who is new to all of this.
941103 - 1.0.0 - initial version
951215 - 1.0.2 - updated for CW7
960707 - 1.0.3 - updated for CW9
---------------------------------------------------------------------- */
#include <Dialogs.h>
#include <Events.h>
#define kTestDLOG 128
#define kMenu 128
#define kItemQuit 1
#define kItemPopup 2
#define kDelay 8
Boolean gDone = false;
pascal Boolean ModalFilter(DialogPtr inDialog, EventRecord *event, short *item)
{
Boolean done = false;
switch (event->what)
{
case mouseDown:
{
WindowPtr myWindow;
RgnHandle theGrayRgn;
short thePart = FindWindow(event->where,&myWindow);
if ((thePart == inDrag) && (myWindow == inDialog))
{
theGrayRgn = GetGrayRgn();
DragWindow(myWindow,event->where,&((**theGrayRgn).rgnBBox));
done = true;
}
}
break;
case keyDown:
{
char typedChar = event->message & 0x00FF;
switch (typedChar)
{
case 0x03: /* the Enter key */
case 0x0D: /* the Return key */
{
short iType,iValue;
long delay;
Handle iHandle;
Rect iRect;
GetDItem(inDialog,kItemQuit,&iType,&iHandle,&iRect);
if (iHandle) /* it exists */
{
iValue = !GetCtlValue((ControlHandle)iHandle);
HiliteControl((ControlHandle)iHandle,1);
Delay(kDelay,&delay);
HiliteControl((ControlHandle)iHandle,0);
}
done = true;
gDone = true;
}
break;
}
}
break;
default:
break;
}
return done;
}
main()
{
short itemType, itemHit, myChoice;
Str255 myTitle;
DialogPtr myDialog;
ModalFilterUPP myDragProc = (ModalFilterUPP)ModalFilter;
Handle myPopHandle;
MenuHandle myMenu;
Rect myPopRect;
InitGraf(&qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(0);
InitCursor();
myDialog = GetNewDialog(kTestDLOG,0,(WindowPtr) -1);
if (myDialog)
{
ShowWindow(myDialog);
while (!gDone)
{
ModalDialog(myDragProc,&itemHit);
switch(itemHit)
{
case kItemQuit:
gDone = true;
break;
case kItemPopup:
/* user selected the popup menu, let's show selection in title bar */
GetDItem(myDialog,kItemPopup,&itemType,&myPopHandle,&myPopRect);
myChoice = GetCtlValue((ControlHandle)myPopHandle);
myMenu = GetMenu(kMenu);
GetItem(myMenu,myChoice,myTitle);
SetWTitle(myDialog,myTitle);
break;
}
}
DisposeDialog(myDialog);
}
}